package cn.three.daoImpl;

import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import cn.three.eneity.Admin;
import cn.three.factory_dao.Admindao;
import cn.three.factory_dao.SqlSessionFactoryUtil;

public class adminloginimpl implements Admindao {

	Admin admin=new Admin();
	public List<Admin> showAdmin() {
		SqlSession se=null;
		List<Admin> list=null;
		try {
			se=SqlSessionFactoryUtil.getSqlSession();
			Admindao dao=se.getMapper(Admindao.class);
	
	
	
		 list=dao.showAdmin();
			
		} catch (Exception e) {
				e.printStackTrace();
		}finally{
			if(se!=null)se.close();
		}
		return list;
	}

	public Admin loginAdmin(String adminName,String adminPwd) {
		
		SqlSession se=null;
		Admin admin=null;
		try {
			se=SqlSessionFactoryUtil.getSqlSession();
			
			Admindao dao=se.getMapper(Admindao.class);
				admin=dao.loginAdmin(adminName,adminPwd);
			
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			if(se!=null)se.close();
		}
		
	
	return admin;
	}

	@Override
	public int addAdmin(Admin admin) {
		int a=0;
		SqlSession se=null;
		try {
			se=SqlSessionFactoryUtil.getSqlSession();
			Admindao dao=se.getMapper(Admindao.class);
			a=dao.addAdmin(admin);
			
		} catch (Exception e) {
		e.printStackTrace();
		}
		finally{
		if(se!=null)se.close();
		}
		return a;
	}

	@Override
	public int updatAdmin(Admin admin) {
		int a=0;
		SqlSession se=null;
		try {
			se=SqlSessionFactoryUtil.getSqlSession();
			Admindao dao=se.getMapper(Admindao.class);
			a=dao.updatAdmin(admin);
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			if(se!=null)se.close();
		}
		return 0;
	}

	@Override
	public List<Admin> showAdminBYid() {
		// TODO Auto-generated method stub
		return null;
	}

}
